package com.vnp.cooking.fragmentKitchen;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.json.JSONException;
import org.json.JSONObject;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.vnp.cooking.DangCongThucActivity;
import com.vnp.cooking.R;
import com.vnp.cooking.UIcontrols.MyCircleImageView;
import com.vnp.cooking.httpclient.HttpClientHelper;
import com.vnp.cooking.httpclient.MyJsonHttpResponseHandler;
import com.vnp.cooking.utils.Common;
import com.vnp.cooking.utils.DecodeUtils;
import com.vnp.cooking.utils.PreferenceHelper;
import com.vnp.cooking.utils.Utils;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.CursorJoiner.Result;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;
import android.widget.Toast;

public class CoverUser1 extends Fragment {

	View v;
	private static final String KEY_CONTENT = "FrgGianbepcuatoi:Content";
	private String mContent = "???";

	// image avatar
	MyCircleImageView imgAvatar;
	TextView txtNameLevel, txtCity;
	DisplayImageOptions options = new DisplayImageOptions.Builder()
			.cacheInMemory(false).cacheOnDisc(false)
			.bitmapConfig(Config.RGB_565).build();

	PreferenceHelper preferenceHelper;

	public static CoverUser1 newInstance(String content) {
		CoverUser1 fragment = new CoverUser1();
		fragment.mContent = content;
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if ((savedInstanceState != null)
				&& savedInstanceState.containsKey(KEY_CONTENT)) {
			mContent = savedInstanceState.getString(KEY_CONTENT);
		}
//		preferenceHelper = new PreferenceHelper(getActivity());
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		v = (View) inflater.inflate(R.layout.cover_canhan_1, container, false);
		
		preferenceHelper = new PreferenceHelper(getActivity());
		
		imgAvatar = (MyCircleImageView) v.findViewById(R.id.img_avatar);
		txtNameLevel = (TextView) v.findViewById(R.id.level_user);
		txtCity = (TextView) v.findViewById(R.id.city_user);
		txtCity.setText(preferenceHelper.getFriendCityName());
		txtNameLevel.setText(preferenceHelper.getFriendLevelname());
		Log.i("DATA", "URL AVATAR: " + preferenceHelper.getFriendUrlAvatar());
		ImageLoader.getInstance().displayImage(
				preferenceHelper.getFriendUrlAvatar(), imgAvatar, options);
		setFont();
		init();
		return v;
	}
	
	private void setFont() {
		txtCity.setTypeface(Utils.getTypefaceRegular(getActivity()), Typeface.BOLD);
		txtNameLevel.setTypeface(Utils.getTypefaceRegular(getActivity()), Typeface.BOLD);
	}

	void init() {
	}

	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putString(KEY_CONTENT, mContent);
	}

}
